import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Put,
  Delete,
  NotFoundException,
} from '@nestjs/common';
import { SongService } from './song.service';
import { CreateSongDto } from './dto/create-song.dto';
import { UpdateSongDto } from './dto/update-song.dto';
import { SongMV } from './entities/song.entity';

@Controller('songs')
export class SongController {
  constructor(private readonly songService: SongService) {}

  // 创建歌曲
  @Post()
  async create(@Body() createSongDto: CreateSongDto): Promise<SongMV> {
    return this.songService.create(createSongDto);
  }

  // 查询所有歌曲
  @Get()
  async findAll(): Promise<SongMV[]> {
    return this.songService.findAll();
  }

  // 查询单个歌曲
  @Get(':id')
  async findOne(@Param('id') id: string): Promise<SongMV> {
    const song = await this.songService.findOne(+id);
    if (!song) {
      throw new NotFoundException('Song not found');
    }
    return song;
  }

  // 更新歌曲
  @Put(':id')
  async update(
    @Param('id') id: string,
    @Body() updateSongDto: UpdateSongDto,
  ): Promise<SongMV> {
    return this.songService.update(+id, updateSongDto);
  }

  // 删除歌曲
  @Delete(':id')
  async remove(@Param('id') id: string): Promise<void> {
    return this.songService.remove(+id);
  }
}